<template>
	<view class="wrapper">
		<view class="top-img" @click="getheadimg">
			<image mode="aspectFill" :src="UserInfo.avatar ?UserInfo.avatar :'../../static/images/user-icon.png'"></image>
		</view>
		
		<view class="content">
			<navigator url="./updateInfo?type=2">
				<view class="info-item">
					<view class="info-name">用户名</view>
					
					<view class="info-right">
						<view class="info-text">{{UserInfo.company ? UserInfo.company:'无'}}</view>
						
						<view class="info-icon">
							<image src="../../static/images/right-icon.png"></image>
						</view>
					</view>
				</view>
			</navigator>
			<navigator url="./changePassword">
				<view class="info-item">
					<view class="info-name">修改密码</view>
					
					<view class="info-right">
						<view class="info-icon">
							<image src="../../static/images/right-icon.png"></image>
						</view>
					</view>
				</view>
			</navigator>
			
			<navigator url="./updateInfo?type=1">
			<view class="info-item">
				<view class="info-name">地址</view>
				
				<view class="info-right">
					<view class="info-text">{{UserInfo.address ? UserInfo.address:'暂无'}}</view>
					
					<view class="info-icon">
						<image src="../../static/images/right-icon.png"></image>
					</view>
				</view>
			</view>
			</navigator>
			
			<view class="out-btn" @click="dropout">退出登录</view>
			
			<view @click="toPrivacy" class="privacy">
				服务协议和隐私策略
			</view>
			<!-- 备案信息 -->
			<view class="record">
				Copyrigh©2020腾蛇tengshemall.com版权所有
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				UserInfo:null,
				imgUrl:this.api.imgUrl,
				num:Math.random()
				
			}
		},
		onShow() {
			this.UserInfo = JSON.parse(uni.getStorageSync('storeMsg'));
		},
		onLoad() {
			
			// if(uni.getStorageSync('store_id') == ''){
			// 	this.$api.errorMsg('你还没有登陆哦~');
			// 	setTimeout(function () {
			// 		uni.redirectTo({
			// 			url:'./logIn'
			// 		})
			// 	}, 1000);
				
			// }
			
		},
		methods: {
			dropout:function(){
				uni.clearStorageSync();
				this.$api.errorMsg('退出登录~');
				setTimeout(function () {
					uni.reLaunch({
						url:'./logIn'
					})
				}, 1000);
			},
			getheadimg:function(){
				var that = this;
				uni.chooseImage({
				    success: (chooseImageRes) => {
				        const tempFilePaths = chooseImageRes.tempFilePaths;
				        uni.uploadFile({
							url: that.$websiteUrl + '/index.php/Store/User/upload_image.html',
							filePath: tempFilePaths[0],
							name: 'headimg',
							success: (uploadFileRes) => {
								var data = JSON.parse(uploadFileRes.data);
								console.log(data)
								if(data.status == '1'){
									this.userEdit(data.data.headimgUrl);
								}else{
									that.$api.errorMsg('网络连接超时，请检查您的网络');
								}
				            }
				        });
				    }
				});
			},
			userEdit:function(headimg){
				var store_id = uni.getStorageSync('store_id');
				var that = this;
				uni.request({
					url: that.$websiteUrl + '/index.php/Store/User/userEdit', 
					data: {store_id:store_id,avatar:headimg},
					method:'POST',
					dataType:'json',
					header: {'content-type' : 'application/x-www-form-urlencoded'},
					success: (resa) => {
						var one = resa.data;
						if(one.status == 1){
							var UserInfo = JSON.parse(uni.getStorageSync('storeMsg'));
							UserInfo.avatar = one.data.avatar;
							that.UserInfo = UserInfo;
							uni.setStorageSync('storeMsg',JSON.stringify(UserInfo))
						}else{
							that.$api.errorMsg(one.message);
							that.scode = false;
						}
						
					},
					fail:(resa)=> {
						that.$api.errorMsg('网络连接超时，请检查您的网络');
					}
				})
			},
			link(url){
				var that =this;
				uni.navigateTo({
					url:url
				})
			},
			toOthersMenu(url){
				var that =this;
				uni.navigateTo({
					url:url
				})
			},
			toPrivacy(){
				uni.navigateTo({
					url:'./privacy'
				})
			}
			
		}
	}
</script>

<style lang="scss">
	@import url('../../common/common.css');
	
	.top-img {
		margin: 50upx auto;
		width: 160upx;
		height: 160upx;
		box-shadow: 0px 0px 20upx 0px rgba(0, 0, 0, 0.15);
		border: 2upx solid #fff;
		border-radius: 50%;
		image {
			border-radius: 50%;
		}
	}
	
	.content {
		padding: 30upx;
	}
	
	.info-item {
		padding: 30upx 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1upx solid #eee;
		.info-name {
			font-size: 28upx;
			color: #999;
		}
		.info-right {
			display: flex;
			align-items: center;
			// border-bottom: 1upx solid #eee;
			.info-img {
				margin-right: 33upx;
				width: 90upx;
				height: 90upx;
				border-radius: 50%;
				image {
					border-radius: 50%;
				}
			}
			.info-text {
				width: 485upx;
				font-size: 28upx;
				line-height: 40upx;
				color: #333;
			}
			.info-icon {
				width: 13upx;
				height: 21upx;
			}
		}
	}
	
	.out-btn {
		margin: 195upx auto 100upx;
		width: 560upx;
		height: 70upx;
		background: #eee;
		border-radius: 40upx;
		font-size: 28upx;
		text-align: center;
		line-height: 70upx;
		letter-spacing: 1px;
		color: #333;
	}
	.record{
		color: #999999;
		font-size:28upx;
		text-align: center;
	}
	.privacy{
		text-align: center;
		color:#2979ff;
	}
</style>
